package com.kaifamiao.dispatch;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/xu/shu")
public class XuShuServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.log( "徐庶开始" );

        // String url = "http://www.kaifamiao.com";
        String url = "/zhu/ge/liang";

        // 设置响应状态代码
        response.setStatus( 302 );
        // 设置响应头中的`location`字段的值
        response.setHeader( "location" , url );

        response.setCharacterEncoding( "UTF-8" );
        response.setHeader("content-type", "text/html;charset=UTF-8" );
        PrintWriter out = response.getWriter();
        out.println( "<h1 style=\"text-align: center\">" );
        out.println( "老刘啊，咱老徐实在对不住啊，...." );
        out.println( "</h1>" );

        this.log( "徐庶退出" );
    }

}
